package cn.ondraw.ragflow.controller;

import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import cn.ondraw.common.core.domain.R;
import cn.ondraw.ragflow.pojo.request.ConvertRequest;
import cn.ondraw.ragflow.pojo.request.File2DocumentRmRequest;
import cn.ondraw.ragflow.service.File2DocumentService;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 文件转换和删除控制器
 */
@RestController
@Slf4j
@RequiredArgsConstructor
@RequestMapping("/v1/file2document")
public class RagFlowFile2DocumentController {
    private final File2DocumentService file2DocumentService;

    /**
     * 转换文件接口
     *
     * @param request 转换请求对象
     * @return 通用响应对象，包含转换结果
     */
    @PostMapping("/convert")
    public R<Object> convert(@RequestBody ConvertRequest request) {
        try {
            return R.ok(file2DocumentService.convert(request));
        } catch (Exception e) {
            return R.fail(e.getMessage());
        }
    }

    /**
     * 删除文件接口
     *
     * @param request 删除请求对象
     * @return 通用响应对象，包含删除结果
     */
    @PostMapping("/rm")
    public R<Object> rm(@RequestBody File2DocumentRmRequest request) {
        try {
            return R.ok(file2DocumentService.rm(request));
        } catch (Exception e) {
            return R.fail(e.getMessage());
        }
    }
}
